/**
 * Copyright 2007 Jason Horman, Pete Aykroyd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.functor;

import java.io.Serializable;

/**
 * A org.functor that takes no arguments and returns no value. Note that this
 * org.functor implements the Runnable interface, making all <code>Procedure</code>s
 * immediately usable in a number of contexts.
 */
public abstract class Procedure implements Runnable, Serializable {

	public static Procedure create(Object context, String expression) {
		return new DynamicProcedure(context, expression);
	}

	public static final Procedure NoOp = new Procedure() {
		public void run() {
		}
	};

	public Procedure then(final Procedure doThis) {
		final Procedure me = this;
		return new Procedure() {
			public void run() {
				me.run();
				doThis.run();
			}
		};
	}
}
